//app.js
var height1=0;
App({
  onLaunch: function () {
    // 展示本地存储能力
    var logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)

    // 登录
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
      }
    })
    // 获取用户信息
    wx.getSetting({
      success: res => {
        if (res.authSetting['scope.userInfo']) {
          // 已经授权，可以直接调用 getUserInfo 获取头像昵称，不会弹框
          wx.getUserInfo({
            success: res => {
              // 可以将 res 发送给后台解码出 unionId
              this.globalData.userInfo = res.userInfo

              // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
              // 所以此处加入 callback 以防止这种情况
              if (this.userInfoReadyCallback) {
                this.userInfoReadyCallback(res)
              }
            }
          })
        }
      }
    })
  },
  onPageScroll: function (ev) {
    var _this = this;
    //当滚动的top值最大或最小时，为什么要做这一步是因为在手机实测小程序的时候会发生滚动条回弹，所以为了处理回弹，设置默认最大最小值
    console.log(ev)
    if (ev.scrollTop <= 0) {
      ev.scrollTop = 0;
    } else if (ev.scrollTop > wx.getSystemInfoSync().windowHeight) {
      ev.scrollTop = wx.getSystemInfoSync().windowHeight;
    }
    //判断浏览器滚动条上下滚动
    if (ev.scrollTop > this.data.scrollTop || ev.scrollTop == wx.getSystemInfoSync().windowHeight) {
      //向下滚动
    } else {
      //向上滚动
    }
    //给scrollTop重新赋值
    setTimeout(function () {
      _this.setData({
        scrollTop: ev.scrollTop
      })
    }, 0)
  },
  onShow(){
    wx.getSystemInfo({
      success: function (res) {
        console.log(res.windowWidth);
        console.log(res.windowHeight);
        var width= res.windowWidth
        var heights = res.windowHeight
        height1=750/(width/heights)-60
        console.log(height1)
      },
    })
  },
  back(){
    wx.navigateBack(1)
  },
  //第一种底部  
  editTabBar: function () {
    //使用getCurrentPages可以获取当前加载中所有的页面对象的一个数组，数组最后一个就是当前页面。
    //获取加载的页面
    var curPageArr = getCurrentPages();
    console.log(curPageArr +"---curPageArr---")
      //获取当前页面的对象
    var curPage = curPageArr[curPageArr.length - 1]; 
    console.log(curPage + "---curPage---")
     
    var pagePath = curPage.route;    //当前页面url

    var page=[]
    page=pagePath.split("/")
     var pp="../"+page[1]+"/"+page[2]
    console.log(pp+"---page")


    var tabBar = this.globalData.tabBar;
    
    for (var i = 0; i < tabBar.length; i++) {
      tabBar[i].active = false;
      if (tabBar[i].url == pp) {
        tabBar[i].active = true;    //根据页面地址设置当前页面状态    
      }
    }
    curPage.setData({
      tabbar: tabBar
     
    });
  },
  //第一种底部  
  editTabBar3: function () {
    //使用getCurrentPages可以获取当前加载中所有的页面对象的一个数组，数组最后一个就是当前页面。
    //获取加载的页面
    var curPageArr = getCurrentPages();
    console.log(curPageArr + "---curPageArr---")
    //获取当前页面的对象
    var curPage = curPageArr[curPageArr.length - 1];
    console.log(curPage + "---curPage---")

    var pagePath = curPage.route;    //当前页面url

    var page = []
    page = pagePath.split("/")
    var pp = "../" + page[1] + "/" + page[2]
    console.log(pp + "---page")


    var tabBar = this.globalData.tabBar3;
    tabBar.height=height1-128
    console.log(tabBar)
    for (var i = 0; i < tabBar.length; i++) {
      tabBar[i].active = false;
      if (tabBar[i].url == pp) {
        tabBar[i].active = true;    //根据页面地址设置当前页面状态    
      }
    }
    console.log(height1)
    
    curPage.setData({
      tabbar: tabBar
    });
  },
  //第二种底部  
  editTabBar2: function () {
    //使用getCurrentPages可以获取当前加载中所有的页面对象的一个数组，数组最后一个就是当前页面。
    //获取加载的页面
    var curPageArr = getCurrentPages();
    console.log(curPageArr + "---curPageArr---")
    //获取当前页面的对象
    var curPage = curPageArr[curPageArr.length - 1];
    console.log(curPage + "---curPage---")

    var pagePath = curPage.route;    //当前页面url

    var page = []
    page = pagePath.split("/")
    var pp = "../" + page[1] + "/" + page[2]
    console.log(pp + "---page")


    var tabBar = this.globalData.tabBar2;
    var length = tabBar.length
    
    for (var i = 0; i < tabBar.length; i++) {
      tabBar[i].active = false;
      if (tabBar[i].url == pp) {
        tabBar[i].active = true;    //根据页面地址设置当前页面状态    
      }
    }
    curPage.setData({
      tabbar: tabBar
    });
  },
  globalData: {
    userInfo: {},
    
    tabBar: [
      {
        text: "首页",
        iconPath: "../../pages/image/home1.png",
        selectedIconPath: "../../pages/image/home2.png",
        url: "../index/index",
        clas: "menu-item1",
        flag: false,
        active: true
      }, {
        text: "维修师",
        iconPath: "../../pages/image/t-wxs1.png",
        selectedIconPath: "../../pages/image/t-wxs2.png",
        url: "../wxs/wxs",
        clas: "menu-item1",
        flag: false,
        active: false
      }, {
        text:"",
        iconPath: "../../pages/image/logo.png",
        selectedIconPath: "../../pages/image/logo.png",
        url: "",
        clas: "menu-item1",
        flag: true,
        active:false
      }, {
        text: "一键快修",
        iconPath: "../../pages/image/bx1.png",
        selectedIconPath: "../../pages/image/bx2.png",
        url: "../xiadan/xiadan",
        clas: "menu-item1",
        flag: false,
        active: false
      }, {
        text: "我的",
        iconPath: "../../pages/image/my1.png",
        selectedIconPath: "../../pages/image/my2.png",
        url: "../mine/mine",
        clas:"menu-item1",
        flag: false,
        active: false
      }
    ],
    tabBar2: [
      {
        text: "首页",
        iconPath: "../../pages/image/home-page.png",
        selectedIconPath: "../../pages/image/home-page.png",
        url: "../index/index",
        clas: "menu-item2",
        flag: false,
        active: true
      }, {
        text: "一键快修",
        iconPath: "../../pages/image/home-page.png",
        selectedIconPath: "../../pages/image/home-page.png",
        url: "../xiadan/xiadan",
        clas: "menu-item2",
        flag: false,
        active: false
      }, {
        text: "客服",
        iconPath: "../../pages/image/home-page.png",
        selectedIconPath: "../../pages/image/home-page.png",
        url: "../mine/mine",
        clas: "menu-item2",
        flag: false,
        active: false
      }
    ],
    
    tabBar3: {
        height:height1,
        list:[{
            text: "我的设备",
            iconPath: "../../pages/image/equip1.png",
            selectedIconPath: "../../pages/image/equip2.png",
            url: "myequipment",
            clas: "menu-item2",
            flag: false,
            active: false
          }, {
            text: "御用维修师",
            iconPath: "../../pages/image/wxs1.png",
            selectedIconPath: "../../pages/image/wxs2.png",
            url: "myenlist",
            clas: "menu-item2",
            flag: false,
            active: false
          }, {
            text: "钱包",
            iconPath: "../../pages/image/mony1.png",
            selectedIconPath: "../../pages/image/mony2.png",
            url: "mycoupon",
            clas: "menu-item2",
            flag: false,
            active: false
          }, {
            text: "亲友号",
            iconPath: "../../pages/image/friend1.png",
            selectedIconPath: "../../pages/image/friend2.png",
            url: "myfriends",
            clas: "menu-item2",
            flag: false,
            active: false
          }, {
            text: "地址管理",
            iconPath: "../../pages/image/addr1.png",
            selectedIconPath: "../../pages/image/addr2.png",
            url: "myaddr",
            clas: "menu-item2",
            flag: false,
            active: false
          }, {
            text: "发票管理",
            iconPath: "../../pages/image/bill1.png",
            selectedIconPath: "../../pages/image/bill2.png",
            url: "mybill",
            clas: "menu-item2",
            flag: false,
            active: false
          }, {
            text: "我的评价",
            iconPath: "../../pages/image/access1.png",
            selectedIconPath: "../../pages/image/access2.png",
            url: "myaccess",
            clas: "menu-item2",
            flag: false,
            active: false
          }, {
            text: "在线客服",
            iconPath: "../../pages/image/kf1.png",
            selectedIconPath: "../../pages/image/kefu2.png",
            url: "myconcat",
            clas: "menu-item2",
            flag: false,
            active: false
          }]
    },
    url:"https://zanwei.natappvip.cc/sell",
    url1: "https://zanwei.mynatapp.cc/sell",
    currentTab:0

  }
})